﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Silverlight3dApp.Learning.Lesson10
{
    public class SpinningEnemy : BasicModel
    {
        protected Matrix _Rotation = Matrix.Identity;

        public Matrix Rotation
        {
            get
            {
                return _Rotation;
            }
        }

        protected Vector3 _Direction;

        private float _yawAngle;
        private float _pitchAngle;
        private float _rollAngle;

        public SpinningEnemy(Model model, Vector3 position, Vector3 direction, float yaw, float pitch, float roll) : base(model)
        {
            _World = Matrix.CreateTranslation(position);
            _Direction = direction;
            _yawAngle = yaw;
            _pitchAngle = pitch;
            _rollAngle = roll;
        }

        public override void Update()
        {
            _World *= Matrix.CreateTranslation(_Direction);
            _Rotation *= Matrix.CreateFromYawPitchRoll(_yawAngle, _pitchAngle, _rollAngle);
            base.Update();
        }

        public override Matrix World
        {
            get
            {
                return _Rotation * _World;
            }
        }
    }
}